package com.huidu.bitrade.controller;

import com.alibaba.fastjson2.JSON;
import com.huidu.bitrade.entity.ExchangeOrder;
import com.huidu.bitrade.entity.ExchangeOrderStatus;
import com.huidu.bitrade.exception.ServiceException;
import com.huidu.bitrade.job.CheckSoldTask;
import com.huidu.bitrade.service.ExchangeOrderService;
import com.huidu.bitrade.service.OrderService;
import com.huidu.bitrade.util.MessageResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping( "otcTest")
@Slf4j
@RequiredArgsConstructor
public class TestController {

    private final KafkaTemplate<String, String> kafkaTemplate;
    private final ExchangeOrderService exchangeOrderService;
    private final OrderService orderService;

    @RequestMapping("cancel")
    public void cancel() {
        List<String> list = orderService.getExchangeOrder();
        for(String orderId:list){
            ExchangeOrder order = exchangeOrderService.findOne(orderId);
            // 发送消息至Exchange系统
            kafkaTemplate.send("exchange-order-cancel", JSON.toJSONString(order));
        }
    }
}
